package com.cool.springcloud.controller;

import com.cool.springcloud.dao.PaymentDao;
import com.cool.springcloud.entity.PaymentEntity;
import com.cool.springcloud.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * @Author ifredomvip@gmail.com
 * @Date 2022/8/18 14:14
 * @Version 1.0.0
 * @Description
 **/
@RestController
@RequestMapping("/payment")
public class PaymentController {
    @Autowired
    private PaymentDao paymentDao;

    @Value("${server.port}")
    private String serverPort;

    @PostMapping("/insertOne")
    public AjaxResult<Integer> insertOne(@RequestBody PaymentEntity payment) throws InterruptedException {

        int result = paymentDao.insertPayment(payment);

        Thread.sleep(5000L);
        return new AjaxResult<>(200, "插入成功,ServerPort:" + serverPort, result);
    }

    @GetMapping("/getOne/{id}")
    public AjaxResult<PaymentEntity> getOne(@PathVariable("id") Long id) {
        PaymentEntity payment = paymentDao.getPaymentById(id);
        System.out.println(payment);
        return new AjaxResult<>(200, "success,ServerPort:" + serverPort, payment);
    }
}
